//
//  TodoCategory.swift
//  memo
//
//  Created by fly on 2019/10/14.
//  Copyright © 2019 Xiang HongFei. All rights reserved.
//

import UIKit

class TodoCategory: NSObject ,NSCoding{
    func encode(with coder: NSCoder) {
        coder.encode(name, forKey: "Name")
        coder.encode(items, forKey: "Items")
        coder.encode(iconImage, forKey: "iconImage")
    }
    
    required init?(coder aDecoder: NSCoder) {
        name = aDecoder.decodeObject(forKey: "Name") as! String
        items = aDecoder.decodeObject(forKey: "Items") as! [TodoItem]
        iconImage = aDecoder.decodeObject(forKey: "iconImage") as! String
        super.init()
    }
    
    
    var name = ""
    var iconImage = "No Icon"
    var items = [TodoItem]()
    
    
    init(name: String){
        self.name = name
        super.init()
    }
    
    func counItems() -> Int {
        var num = 0
        
        for item in items where !item.checked {
            num += 1
        }
        
        return num
    }
}
